package com.xnyzc.lhy.didi.mapper.sys;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xnyzc.lhy.order.entity.sidebar.OaSysOffice;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface OaSysOfficeMapper extends BaseMapper<OaSysOffice> {

    @Select("SELECT office_id " +
            "FROM oa_sys_office office " +
            "LEFT JOIN oa_sys_area area " +
            "ON office.area_id=area.area_id " +
            "WHERE office.parent_id=1 AND area.ad_code=#{cityId}")
    @Deprecated //弃用
    Long getCompanyByAdCode(@Param("cityId") String cityId);

    @Select("SELECT office_id,office.expand1 " +
            "FROM oa_sys_office office " +
            "LEFT JOIN oa_sys_area area " +
            "ON office.area_id=area.area_id " +
            "WHERE office.parent_id <> 1 AND area.ad_code=#{cityId}")
    List<OaSysOffice> getCompanysByAdCode(@Param("cityId") String cityId);

    @Select("SELECT \n" +
            "oa_sys_office.office_id AS officeId,\n" +
            "oa_d_user.driver_id AS driverId,\n" +
            " \n" +
            "oa_sys_office.primary_person AS driverName,\n" +
            " \n" +
            "oa_sys_office.phone AS driverPhone, \n" +
            "oa_d_driver_vehicle.vehicle_id AS vehId, \n" +
            "\n" +
            "oa_sys_vehicle.veh_no AS vehNo, \n" +
            "\n" +
            "oa_sys_vehicle_mdict.expand3 AS vehType, \n" +
            "oa_sys_vehicle_mdict.name AS vehicleBrandDetail, \n" +
            "re.cname AS vehicleBrand,   \n" +
            "oa_sys_dict.label AS vehColor \n" +
            "FROM oa_sys_user \n" +
            "LEFT JOIN oa_sys_office \n" +
            "ON oa_sys_user.office_id=oa_sys_office.office_id \n" +
            "LEFT JOIN oa_d_user_office \n" +
            "ON oa_sys_office.office_id=oa_d_user_office.office_id \n" +
            "LEFT JOIN oa_d_user\n" +
            " \n" +
            "ON oa_d_user_office.driver_id=oa_d_user.driver_id  \n" +
            "\n" +
            "\n" +
            "LEFT JOIN oa_d_driver_vehicle  \n" +
            "\n" +
            "ON oa_d_user.driver_id=oa_d_driver_vehicle.driver_id  \n" +
            "\n" +
            "\n" +
            "LEFT JOIN oa_sys_vehicle  \n" +
            "\n" +
            "ON oa_d_driver_vehicle.vehicle_id=oa_sys_vehicle.vehicle_id \n" +
            " \n" +
            "\n" +
            "LEFT JOIN oa_sys_vehicle_mdict  \n" +
            "\n" +
            "ON oa_sys_vehicle.code=oa_sys_vehicle_mdict.code  \n" +
            "\n" +
            "LEFT JOIN ( \n" +
                    "SELECT \n" +
                        "a.parent_id AS apid,  \n" +
                        "c.NAME AS cname  \n" +
                        "FROM  \n" +
                                "oa_sys_vehicle_mdict a  \n" +
                        "LEFT JOIN oa_sys_vehicle_mdict b ON a.parent_id = b.mdict_id  \n" +
                        "LEFT JOIN oa_sys_vehicle_mdict c ON b.parent_id = c.mdict_id  \n" +
                        "WHERE c.expand1=1 \n"+
                   " ) re  \n" +
            "ON re.apid=oa_sys_vehicle_mdict.parent_id  \n" +
            "\n" +
            "LEFT JOIN oa_sys_dict  \n" +
            "\n" +
            "ON oa_sys_vehicle.veh_color=oa_sys_dict.value\n" +
            "WHERE oa_sys_vehicle.veh_type=${vehType} AND oa_sys_office.office_id=${officeId} AND oa_sys_dict.type='vegicle_color_type' " +
            "order by oa_d_user.update_time limit 1")
    /**
     * 司机信息用公司管理员，车辆信息则从公司下面的供应商中随机选择一辆车构成
     *
     * @param officeId
     * @return
     */
    Map<String, Object> getCompanyDriver(@Param("officeId") Long officeId, @Param("vehType") Integer vehType);
}
